import cv2
import matplotlib.pyplot as plt

def bean1():
    bean1 = cv2.imread('7/001.jpg')

    h1 = cv2.calcHist([bean1], [0], None, [256], [0, 256])
    his1 = cv2.normalize(h1, None, 1, 0, cv2.NORM_L1)
    
    fig1 = plt.figure(figsize=(10, 8))
    fig1.add_subplot(1, 2, 1)
    plt.imshow(bean1)
    plt.title('bean1')
    fig1.add_subplot(1, 2, 2)
    plt.plot(his1)
    plt.title('bean1_hist')

    plt.show()

def bean2():
    bean2 = cv2.imread('7/002.jpg')

    h2 = cv2.calcHist([bean2], [0], None, [256], [0, 256])
    his2 = cv2.normalize(h2, None, 1, 0, cv2.NORM_L1)

    fig2 = plt.figure(figsize=(10, 8))
    fig2.add_subplot(1, 2, 1)
    plt.imshow(bean2)
    plt.title('bean2')
    fig2.add_subplot(1, 2, 2)
    plt.plot(his2)
    plt.title('bean2_hist')

    plt.show()

def bean3():
    bean3 = cv2.imread('7/003.jpg')

    h3 = cv2.calcHist([bean3], [0], None, [256], [0, 256])
    his3 = cv2.normalize(h3, None, 1, 0, cv2.NORM_L1)

    fig3 = plt.figure(figsize=(10, 8))
    fig3.add_subplot(1, 2, 1)
    plt.imshow(bean3)
    plt.title('bean3')
    fig3.add_subplot(1, 2, 2)
    plt.plot(his3)
    plt.title('bean3_hist')

    plt.show()

def bean4():
    bean4 = cv2.imread('7/004.jpg')

    h4 = cv2.calcHist([bean4], [0], None, [256], [0, 256])
    his4 = cv2.normalize(h4, None, 1, 0, cv2.NORM_L1)
    
    fig4 = plt.figure(figsize=(10, 8))
    fig4.add_subplot(1, 2, 1)
    plt.imshow(bean4)
    plt.title('bean4')
    fig4.add_subplot(1, 2, 2)
    plt.plot(his4)
    plt.title('bean4_hist')

    plt.show()

def main():
    bean1()
    bean2()
    bean3()
    bean4()

if __name__ == '__main__':
    main()